home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / bin / DXUtils / AppWizard / DXAppwiz.awx / TEMPLATE / DMUTIL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-25  |  22.6 KB  |  691 lines

  1. //-----------------------------------------------------------------------------
  2. // File: DMUtil.cpp
  3. //
  4. // Desc: DirectMusic framework classes for playing DirectMusic segments and
  5. //       DirectMusic scripts. Feel free to use this class as a starting point 
  6. //       for adding extra functionality.
  7. //-----------------------------------------------------------------------------
  8. #define STRICT
  9. $$IF(DLG)
  10. #include "stdafx.h"
  11. $$ENDIF
  12. #include <dmusicc.h>
  13. #include <dmusici.h>
  14. #include <dsound.h>
  15. #include <dxerr8.h>
  16. #include "DMUtil.h"
  17. #include "DXUtil.h"
  18.  
  19.  
  20.  
  21.  
  22. //-----------------------------------------------------------------------------
  23. // Name: CMusicManager::CMusicManager()
  24. // Desc: Constructs the class
  25. //-----------------------------------------------------------------------------
  26. CMusicManager::CMusicManager()
  27. {
  28.     m_pLoader       = NULL;
  29.     m_pPerformance  = NULL;
  30.     
  31.     // Initialize COM
  32.     HRESULT hr = CoInitialize(NULL);
  33.     m_bCleanupCOM = SUCCEEDED(hr);
  34. }
  35.  
  36.  
  37.  
  38.  
  39. //-----------------------------------------------------------------------------
  40. // Name: CMusicManager::~CMusicManager()
  41. // Desc: Destroys the class
  42. //-----------------------------------------------------------------------------
  43. CMusicManager::~CMusicManager()
  44. {
  45.     SAFE_RELEASE( m_pLoader ); 
  46.  
  47.     if( m_pPerformance )
  48.     {
  49.         // If there is any music playing, stop it.
  50.         m_pPerformance->Stop( NULL, NULL, 0, 0 );
  51.         m_pPerformance->CloseDown();
  52.  
  53.         SAFE_RELEASE( m_pPerformance );
  54.     }
  55.  
  56.     if( m_bCleanupCOM )
  57.         CoUninitialize();
  58. }
  59.  
  60.  
  61.  
  62.  
  63. //-----------------------------------------------------------------------------
  64. // Name: CMusicManager::Initialize()
  65. // Desc: Inits DirectMusic using a standard audio path
  66. //-----------------------------------------------------------------------------
  67. HRESULT CMusicManager::Initialize( HWND hWnd, DWORD dwPChannels, DWORD dwDefaultPathType )
  68. {
  69.     HRESULT hr;
  70.  
  71.     // Create loader object
  72.     if( FAILED( hr = CoCreateInstance( CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC, 
  73.                                        IID_IDirectMusicLoader8, (void**)&m_pLoader ) ) )
  74.         return DXTRACE_ERR( TEXT("CoCreateInstance"), hr );
  75.  
  76.     // Create performance object
  77.     if( FAILED( hr = CoCreateInstance( CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC, 
  78.                                        IID_IDirectMusicPerformance8, (void**)&m_pPerformance ) ) )
  79.         return DXTRACE_ERR( TEXT("CoCreateInstance"), hr );
  80.  
  81.     // Initialize the performance with the standard audio path.
  82.     // This initializes both DirectMusic and DirectSound and 
  83.     // sets up the synthesizer. Typcially its easist to use an 
  84.     // audio path for playing music and sound effects.
  85.     if( FAILED( hr = m_pPerformance->InitAudio( NULL, NULL, hWnd, dwDefaultPathType, 
  86.                                                 dwPChannels, DMUS_AUDIOF_ALL, NULL ) ) )
  87.     {
  88.         if( hr == DSERR_NODRIVER )
  89.         {
  90.             DXTRACE( "Warning: No sound card found\n" );
  91.             return hr;
  92.         }
  93.  
  94.         return DXTRACE_ERR( TEXT("InitAudio"), hr );
  95.     }
  96.  
  97.     return S_OK;
  98. }
  99.  
  100.  
  101.  
  102.  
  103. //-----------------------------------------------------------------------------
  104. // Name: CMusicManager::SetSearchDirectory()
  105. // Desc: Sets the search directory.  If not called, the current working
  106. //       directory is used to load content.
  107. //-----------------------------------------------------------------------------
  108. HRESULT CMusicManager::SetSearchDirectory( const TCHAR* strMediaPath )
  109. {
  110.     if( NULL == m_pLoader )
  111.         return E_UNEXPECTED;
  112.  
  113.     // DMusic only takes wide strings
  114.     WCHAR wstrMediaPath[MAX_PATH];
  115.     DXUtil_ConvertGenericStringToWide( wstrMediaPath, strMediaPath );
  116.  
  117.     return m_pLoader->SetSearchDirectory( GUID_DirectMusicAllTypes, 
  118.                                           wstrMediaPath, FALSE );
  119. }
  120.  
  121.  
  122.  
  123.  
  124. //-----------------------------------------------------------------------------
  125. // Name: CMusicManager::GetDefaultAudioPath()
  126. // Desc: 
  127. //-----------------------------------------------------------------------------
  128. IDirectMusicAudioPath8* CMusicManager::GetDefaultAudioPath()
  129. {
  130.     IDirectMusicAudioPath8* pAudioPath = NULL;
  131.     if( NULL == m_pPerformance )
  132.         return NULL;
  133.  
  134.     m_pPerformance->GetDefaultAudioPath( &pAudioPath );
  135.     return pAudioPath;
  136. }
  137.  
  138.  
  139.  
  140.  
  141. //-----------------------------------------------------------------------------
  142. // Name: CMusicManager::CollectGarbage()
  143. // Desc: Tells the loader to cleanup any garbage from previously 
  144. //       released objects.
  145. //-----------------------------------------------------------------------------
  146. VOID CMusicManager::CollectGarbage()
  147. {
  148.     if( m_pLoader )
  149.         m_pLoader->CollectGarbage();
  150. }
  151.  
  152.  
  153.  
  154.  
  155. //-----------------------------------------------------------------------------
  156. // Name: CMusicManager::CreateSegmentFromFile()
  157. // Desc: 
  158. //-----------------------------------------------------------------------------
  159. HRESULT CMusicManager::CreateSegmentFromFile( CMusicSegment** ppSegment, 
  160.                                               TCHAR* strFileName, 
  161.                                               BOOL bDownloadNow,
  162.                                               BOOL bIsMidiFile )
  163. {
  164.     HRESULT               hr;
  165.     IDirectMusicSegment8* pSegment = NULL;
  166.  
  167.     // DMusic only takes wide strings
  168.     WCHAR wstrFileName[MAX_PATH];
  169.     DXUtil_ConvertGenericStringToWide( wstrFileName, strFileName );
  170.  
  171.     if ( FAILED( hr = m_pLoader->LoadObjectFromFile( CLSID_DirectMusicSegment,
  172.                                                      IID_IDirectMusicSegment8,
  173.                                                      wstrFileName,
  174.                                                      (LPVOID*) &pSegment ) ) )
  175.     {
  176.         if( hr == DMUS_E_LOADER_FAILEDOPEN )
  177.             return hr;
  178.         return DXTRACE_ERR( TEXT("LoadObjectFromFile"), hr );
  179.     }
  180.  
  181.     *ppSegment = new CMusicSegment( m_pPerformance, m_pLoader, pSegment );
  182.     if (!*ppSegment)
  183.         return E_OUTOFMEMORY;
  184.  
  185.     if( bIsMidiFile )
  186.     {
  187.         if( FAILED( hr = pSegment->SetParam( GUID_StandardMIDIFile, 
  188.                                              0xFFFFFFFF, 0, 0, NULL ) ) )
  189.             return DXTRACE_ERR( TEXT("SetParam"), hr );
  190.     }
  191.  
  192.     if( bDownloadNow )
  193.     {
  194.         if( FAILED( hr = (*ppSegment)->Download() ) )
  195.             return DXTRACE_ERR( TEXT("Download"), hr );
  196.     }
  197.  
  198.     return S_OK;
  199. }
  200.  
  201.  
  202.  
  203.  
  204. //-----------------------------------------------------------------------------
  205. // Name: CMusicManager::CreateSegmentFromResource()
  206. // Desc: 
  207. //-----------------------------------------------------------------------------
  208. HRESULT CMusicManager::CreateSegmentFromResource( CMusicSegment** ppSegment, 
  209.                                                   TCHAR* strResource,
  210.                                                   TCHAR* strResourceType,
  211.                                                   BOOL bDownloadNow,
  212.                                                   BOOL bIsMidiFile )
  213. {
  214.     HRESULT               hr;
  215.     IDirectMusicSegment8* pSegment      = NULL;
  216.     HRSRC                 hres          = NULL;
  217.     void*                 pMem          = NULL;
  218.     DWORD                 dwSize        = 0;
  219.     DMUS_OBJECTDESC       objdesc;
  220.  
  221.     // Find the resource
  222.     hres = FindResource( NULL,strResource,strResourceType );
  223.     if( NULL == hres ) 
  224.         return E_FAIL;
  225.  
  226.     // Load the resource
  227.     pMem = (void*)LoadResource( NULL, hres );
  228.     if( NULL == pMem ) 
  229.         return E_FAIL;
  230.  
  231.     // Store the size of the resource
  232.     dwSize = SizeofResource( NULL, hres ); 
  233.     
  234.     // Set up our object description 
  235.     ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  236.     objdesc.dwSize = sizeof(DMUS_OBJECTDESC);
  237.     objdesc.dwValidData = DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS;
  238.     objdesc.guidClass = CLSID_DirectMusicSegment;
  239.     objdesc.llMemLength =(LONGLONG)dwSize;
  240.     objdesc.pbMemData = (BYTE*)pMem;
  241.     
  242.     if (FAILED ( hr = m_pLoader->GetObject( &objdesc,
  243.                                             IID_IDirectMusicSegment8,
  244.                                             (void**)&pSegment ) ) )
  245.     {
  246.         if( hr == DMUS_E_LOADER_FAILEDOPEN )
  247.             return hr;
  248.         return DXTRACE_ERR( TEXT("LoadObjectFromFile"), hr );
  249.     }
  250.  
  251.     *ppSegment = new CMusicSegment( m_pPerformance, m_pLoader, pSegment );
  252.     if( NULL == *ppSegment )
  253.         return E_OUTOFMEMORY;
  254.  
  255.     if( bIsMidiFile )
  256.     {
  257.         // Do this to make sure that the default General MIDI set 
  258.         // is connected appropriately to the MIDI file and 
  259.         // all instruments sound correct.                  
  260.         if( FAILED( hr = pSegment->SetParam( GUID_StandardMIDIFile, 
  261.                                              0xFFFFFFFF, 0, 0, NULL ) ) )
  262.             return DXTRACE_ERR( TEXT("SetParam"), hr );
  263.     }
  264.  
  265.     if( bDownloadNow )
  266.     {
  267.         // The segment needs to be download first before playing.  
  268.         // However, some apps may want to wait before calling this 
  269.         // to because the download allocates memory for the 
  270.         // instruments. The more instruments currently downloaded, 
  271.         // the more memory is in use by the synthesizer.
  272.         if( FAILED( hr = (*ppSegment)->Download() ) )
  273.             return DXTRACE_ERR( TEXT("Download"), hr );
  274.     }
  275.  
  276.     return S_OK;
  277. }
  278.  
  279.  
  280.  
  281.  
  282. //-----------------------------------------------------------------------------
  283. // Name: CMusicManager::CreateScriptFromFile()
  284. // Desc: 
  285. //-----------------------------------------------------------------------------
  286. HRESULT CMusicManager::CreateScriptFromFile( CMusicScript** ppScript, 
  287.                                              TCHAR* strFileName )
  288. {
  289.     HRESULT               hr;
  290.     IDirectMusicScript* pScript = NULL;
  291.  
  292.     // DMusic only takes wide strings
  293.     WCHAR wstrFileName[MAX_PATH];
  294.     DXUtil_ConvertGenericStringToWide( wstrFileName, strFileName );
  295.     
  296.     if ( FAILED( hr = m_pLoader->LoadObjectFromFile( CLSID_DirectMusicScript,
  297.                                                      IID_IDirectMusicScript8,
  298.                                                      wstrFileName,
  299.                                                      (LPVOID*) &pScript ) ) )
  300.         return DXTRACE_ERR_NOMSGBOX( TEXT("LoadObjectFromFile"), hr );
  301.  
  302.     if ( FAILED( hr = pScript->Init( m_pPerformance, NULL ) ) )
  303.         return DXTRACE_ERR( TEXT("Init"), hr );
  304.  
  305.     *ppScript = new CMusicScript( m_pPerformance, m_pLoader, pScript );
  306.     if (!*ppScript)
  307.         return E_OUTOFMEMORY;
  308.  
  309.     return hr;
  310. }
  311.  
  312.  
  313.  
  314.  
  315. //-----------------------------------------------------------------------------
  316. // Name: CMusicManager::CreateChordMapFromFile()
  317. // Desc: 
  318. //-----------------------------------------------------------------------------
  319. HRESULT CMusicManager::CreateChordMapFromFile( IDirectMusicChordMap8** ppChordMap, 
  320.                                                TCHAR* strFileName )
  321. {
  322.     // DMusic only takes wide strings
  323.     WCHAR wstrFileName[MAX_PATH];
  324.     DXUtil_ConvertGenericStringToWide( wstrFileName, strFileName );
  325.  
  326.     return m_pLoader->LoadObjectFromFile( CLSID_DirectMusicChordMap,
  327.                                           IID_IDirectMusicChordMap8,
  328.                                           wstrFileName, (LPVOID*) ppChordMap );
  329. }
  330.  
  331.  
  332.  
  333.  
  334. //-----------------------------------------------------------------------------
  335. // Name: CMusicManager::CreateChordMapFromFile()
  336. // Desc: 
  337. //-----------------------------------------------------------------------------
  338. HRESULT CMusicManager::CreateStyleFromFile( IDirectMusicStyle8** ppStyle, 
  339.                                             TCHAR* strFileName )
  340. {
  341.     // DMusic only takes wide strings
  342.     WCHAR wstrFileName[MAX_PATH];
  343.     DXUtil_ConvertGenericStringToWide( wstrFileName, strFileName );
  344.  
  345.     return m_pLoader->LoadObjectFromFile( CLSID_DirectMusicStyle,
  346.                                           IID_IDirectMusicStyle8,
  347.                                           wstrFileName, (LPVOID*) ppStyle );
  348. }
  349.  
  350.  
  351.  
  352.  
  353. //-----------------------------------------------------------------------------
  354. // Name: CMusicManager::GetMotifFromStyle()
  355. // Desc: 
  356. //-----------------------------------------------------------------------------
  357. HRESULT CMusicManager::GetMotifFromStyle( IDirectMusicSegment8** ppMotif8, 
  358.                                           TCHAR* strStyle, TCHAR* strMotif )
  359. {       
  360.     HRESULT              hr;
  361.     IDirectMusicStyle8*  pStyle = NULL;
  362.     IDirectMusicSegment* pMotif = NULL;
  363.  
  364.     if( FAILED( hr = CreateStyleFromFile( &pStyle, strStyle ) ) )
  365.         return DXTRACE_ERR( TEXT("CreateStyleFromFile"), hr );
  366.  
  367.     if( pStyle )
  368.     {
  369.         // DMusic only takes wide strings
  370.         WCHAR wstrMotif[MAX_PATH];
  371.         DXUtil_ConvertGenericStringToWide( wstrMotif, strMotif );
  372.  
  373.         hr = pStyle->GetMotif( wstrMotif, &pMotif );
  374.         SAFE_RELEASE( pStyle );
  375.  
  376.         if( FAILED( hr ) )
  377.             return DXTRACE_ERR( TEXT("GetMotif"), hr );
  378.  
  379.         pMotif->QueryInterface( IID_IDirectMusicSegment8, (LPVOID*) ppMotif8 );
  380.     }
  381.  
  382.     return S_OK;
  383. }
  384.  
  385.  
  386.  
  387.  
  388. //-----------------------------------------------------------------------------
  389. // Name: CMusicSegment::CMusicSegment()
  390. // Desc: Constructs the class
  391. //-----------------------------------------------------------------------------
  392. CMusicSegment::CMusicSegment( IDirectMusicPerformance8* pPerformance, 
  393.                               IDirectMusicLoader8*      pLoader,
  394.                               IDirectMusicSegment8*     pSegment )
  395. {
  396.     m_pPerformance          = pPerformance;
  397.     m_pLoader               = pLoader;
  398.     m_pSegment              = pSegment;
  399.     m_pEmbeddedAudioPath    = NULL;
  400.     m_bDownloaded           = FALSE;
  401.     
  402.     // Try to pull out an audio path from the segment itself if there is one.
  403.     // This embedded audio path will be used instead of the default
  404.     // audio path if the app doesn't wish to use an overriding audio path.
  405.     IUnknown* pConfig = NULL;
  406.     if( SUCCEEDED( m_pSegment->GetAudioPathConfig( &pConfig ) ) )
  407.     {
  408.         m_pPerformance->CreateAudioPath( pConfig, TRUE, &m_pEmbeddedAudioPath );
  409.         SAFE_RELEASE( pConfig );
  410.     } 
  411.  
  412. }
  413.  
  414.  
  415.  
  416.  
  417. //-----------------------------------------------------------------------------
  418. // Name: CMusicSegment::~CMusicSegment()
  419. // Desc: Destroys the class
  420. //-----------------------------------------------------------------------------
  421. CMusicSegment::~CMusicSegment()
  422. {
  423.     if( m_pSegment )
  424.     {
  425.         // Tell the loader that this object should now be released
  426.         if( m_pLoader )
  427.             m_pLoader->ReleaseObjectByUnknown( m_pSegment );
  428.  
  429.         if( m_bDownloaded )
  430.         {
  431.             if( m_pEmbeddedAudioPath )
  432.                 m_pSegment->Unload( m_pEmbeddedAudioPath );
  433.             else
  434.                 m_pSegment->Unload( m_pPerformance );
  435.         }
  436.  
  437.         SAFE_RELEASE( m_pEmbeddedAudioPath ); 
  438.         SAFE_RELEASE( m_pSegment ); 
  439.     }
  440.  
  441.     m_pPerformance = NULL;
  442. }
  443.  
  444.  
  445.  
  446.  
  447. //-----------------------------------------------------------------------------
  448. // Name: CMusicSegment::Play()
  449. // Desc: Plays the sound using voice management flags.  Pass in DSBPLAY_LOOPING
  450. //       in the dwFlags to loop the sound
  451. //-----------------------------------------------------------------------------
  452. HRESULT CMusicSegment::Play( DWORD dwFlags, IDirectMusicAudioPath8* pAudioPath )
  453. {
  454.     if( m_pSegment == NULL || m_pPerformance == NULL )
  455.         return CO_E_NOTINITIALIZED;
  456.  
  457.     if( !m_bDownloaded )
  458.         return E_FAIL;
  459.  
  460.     // If an audio path was passed in then use it, otherwise
  461.     // use the embedded audio path if there was one.
  462.     if( pAudioPath == NULL && m_pEmbeddedAudioPath != NULL )
  463.         pAudioPath = m_pEmbeddedAudioPath;
  464.         
  465.     // If pAudioPath is NULL then this plays on the default audio path.
  466.     return m_pPerformance->PlaySegmentEx( m_pSegment, 0, NULL, dwFlags, 
  467.                                           0, 0, NULL, pAudioPath );
  468. }
  469.  
  470.  
  471.  
  472.  
  473.  
  474. //-----------------------------------------------------------------------------
  475. // Name: CMusicSegment::Download()
  476. // Desc: 
  477. //-----------------------------------------------------------------------------
  478. HRESULT CMusicSegment::Download( IDirectMusicAudioPath8* pAudioPath )
  479. {
  480.     HRESULT hr;
  481.     
  482.     if( m_pSegment == NULL )
  483.         return CO_E_NOTINITIALIZED;
  484.  
  485.     // If no audio path was passed in, then download
  486.     // to the embedded audio path if it exists 
  487.     // else download to the performance
  488.     if( pAudioPath == NULL )
  489.     {
  490.         if( m_pEmbeddedAudioPath )
  491.             hr = m_pSegment->Download( m_pEmbeddedAudioPath );
  492.         else    
  493.             hr = m_pSegment->Download( m_pPerformance );
  494.     }
  495.     else
  496.     {
  497.         hr = m_pSegment->Download( pAudioPath );
  498.     }
  499.     
  500.     if ( SUCCEEDED( hr ) )
  501.         m_bDownloaded = TRUE;
  502.         
  503.     return hr;
  504. }
  505.  
  506.  
  507.  
  508.  
  509. //-----------------------------------------------------------------------------
  510. // Name: CMusicSegment::Unload()
  511. // Desc: 
  512. //-----------------------------------------------------------------------------
  513. HRESULT CMusicSegment::Unload( IDirectMusicAudioPath8* pAudioPath )
  514. {
  515.     HRESULT hr;
  516.     
  517.     if( m_pSegment == NULL )
  518.         return CO_E_NOTINITIALIZED;
  519.  
  520.     // If no audio path was passed in, then unload 
  521.     // from the embedded audio path if it exists 
  522.     // else unload from the performance
  523.     if( pAudioPath == NULL )
  524.     {
  525.         if( m_pEmbeddedAudioPath )
  526.             hr = m_pSegment->Unload( m_pEmbeddedAudioPath );
  527.         else    
  528.             hr = m_pSegment->Unload( m_pPerformance );
  529.     }
  530.     else
  531.     {
  532.         hr = m_pSegment->Unload( pAudioPath );
  533.     }
  534.         
  535.     if ( SUCCEEDED( hr ) )
  536.         m_bDownloaded = FALSE;
  537.  
  538.     return hr;
  539. }
  540.  
  541.  
  542.  
  543.  
  544. //-----------------------------------------------------------------------------
  545. // Name: CMusicSegment::IsPlaying()
  546. // Desc: 
  547. //-----------------------------------------------------------------------------
  548. BOOL CMusicSegment::IsPlaying()
  549. {
  550.     if( m_pSegment == NULL || m_pPerformance == NULL )
  551.         return CO_E_NOTINITIALIZED;
  552.  
  553.     return ( m_pPerformance->IsPlaying( m_pSegment, NULL ) == S_OK );
  554. }
  555.  
  556.  
  557.  
  558.  
  559. //-----------------------------------------------------------------------------
  560. // Name: CMusicSegment::Stop()
  561. // Desc: Stops the sound from playing
  562. //-----------------------------------------------------------------------------
  563. HRESULT CMusicSegment::Stop( DWORD dwFlags )
  564. {
  565.     if( m_pSegment == NULL || m_pPerformance == NULL )
  566.         return CO_E_NOTINITIALIZED;
  567.  
  568.     return m_pPerformance->Stop( m_pSegment, NULL, 0, dwFlags );;
  569. }
  570.  
  571.  
  572.  
  573.  
  574. //-----------------------------------------------------------------------------
  575. // Name: CMusicSegment::SetRepeats()
  576. // Desc: 
  577. //-----------------------------------------------------------------------------
  578. HRESULT CMusicSegment::SetRepeats( DWORD dwRepeats )
  579. {
  580.     if( m_pSegment == NULL )
  581.         return CO_E_NOTINITIALIZED;
  582.  
  583.     return m_pSegment->SetRepeats( dwRepeats );
  584. }
  585.  
  586.  
  587.  
  588.  
  589. //-----------------------------------------------------------------------------
  590. // Name: CMusicSegment::GetStyle()
  591. // Desc: 
  592. //-----------------------------------------------------------------------------
  593. HRESULT CMusicSegment::GetStyle( IDirectMusicStyle8** ppStyle, DWORD dwStyleIndex )
  594. {
  595.     // Get the Style from the Segment by calling the Segment's GetData() with
  596.     // the data type GUID_StyleTrackStyle. 0xffffffff indicates to look at
  597.     // tracks in all TrackGroups in the segment. The first 0 indicates to
  598.     // retrieve the Style from the first Track  in the indicated TrackGroup.
  599.     // The second 0 indicates to retrieve the Style from the beginning of the
  600.     // segment, i.e. time 0 in Segment time. If this Segment was loaded from a
  601.     // section file, there is only one Style and it is at time 0.
  602.     return m_pSegment->GetParam( GUID_IDirectMusicStyle, 0xffffffff, dwStyleIndex, 
  603.                                  0, NULL, (VOID*)ppStyle );
  604. }
  605.  
  606.  
  607.  
  608. //-----------------------------------------------------------------------------
  609. // Name: CMusicScript::CMusicScript()
  610. // Desc: Constructs the class
  611. //-----------------------------------------------------------------------------
  612. CMusicScript::CMusicScript( IDirectMusicPerformance8* pPerformance, 
  613.                             IDirectMusicLoader8* pLoader,                   
  614.                             IDirectMusicScript8* pScript )
  615. {
  616.     m_pPerformance = pPerformance;
  617.     m_pLoader      = pLoader;
  618.     m_pScript      = pScript;
  619. }
  620.  
  621.  
  622.  
  623.  
  624. //-----------------------------------------------------------------------------
  625. // Name: CMusicScript::~CMusicScript()
  626. // Desc: Destroys the class
  627. //-----------------------------------------------------------------------------
  628. CMusicScript::~CMusicScript()
  629. {
  630.     if( m_pLoader )
  631.     {
  632.         // Tell the loader that this object should now be released
  633.         m_pLoader->ReleaseObjectByUnknown( m_pScript );
  634.         m_pLoader = NULL;
  635.     }
  636.  
  637.     SAFE_RELEASE( m_pScript ); 
  638.     m_pPerformance = NULL;
  639. }
  640.  
  641.  
  642.  
  643.  
  644. //-----------------------------------------------------------------------------
  645. // Name: CMusicScript::Play()
  646. // Desc: Calls a routine in the script
  647. //-----------------------------------------------------------------------------
  648. HRESULT CMusicScript::CallRoutine( TCHAR* strRoutine )
  649. {
  650.     // DMusic only takes wide strings
  651.     WCHAR wstrRoutine[MAX_PATH];
  652.     DXUtil_ConvertGenericStringToWide( wstrRoutine, strRoutine );
  653.  
  654.     return m_pScript->CallRoutine( wstrRoutine, NULL );
  655. }
  656.  
  657.  
  658.  
  659.  
  660. //-----------------------------------------------------------------------------
  661. // Name: CMusicScript::SetVariableNumber()
  662. // Desc: Sets the value of a variable in the script
  663. //-----------------------------------------------------------------------------
  664. HRESULT CMusicScript::SetVariableNumber( TCHAR* strVariable, LONG lValue )
  665. {
  666.     // DMusic only takes wide strings
  667.     WCHAR wstrVariable[MAX_PATH];
  668.     DXUtil_ConvertGenericStringToWide( wstrVariable, strVariable );
  669.  
  670.     return m_pScript->SetVariableNumber( wstrVariable, lValue, NULL );
  671. }
  672.  
  673.  
  674.  
  675.  
  676. //-----------------------------------------------------------------------------
  677. // Name: CMusicScript::GetVariableNumber()
  678. // Desc: Gets the value of a variable in the script
  679. //-----------------------------------------------------------------------------
  680. HRESULT CMusicScript::GetVariableNumber( TCHAR* strVariable, LONG* plValue )
  681. {
  682.     // DMusic only takes wide strings
  683.     WCHAR wstrVariable[MAX_PATH];
  684.     DXUtil_ConvertGenericStringToWide( wstrVariable, strVariable );
  685.  
  686.     return m_pScript->GetVariableNumber( wstrVariable, plValue, NULL );
  687. }
  688.  
  689.  
  690.  
  691.